package cc.chinagps.gateway.unit.eg.upload.cmds;

import org.apache.log4j.Logger;
import org.seg.lib.util.Util;

import cc.chinagps.gateway.log.LogManager;
import cc.chinagps.gateway.unit.UnitServer;
import cc.chinagps.gateway.unit.UnitSocketSession;
import cc.chinagps.gateway.unit.eg.pkg.EGPackage;
import cc.chinagps.gateway.unit.eg.util.EGTimeFormatUtil;
import cc.chinagps.gateway.util.HexUtil;

public class CmdA0 extends CheckLoginHandler {
	private Logger logger_debug = Logger.getLogger(LogManager.LOGGER_NAME_DEBUG);

	@Override
	public boolean handlerPackageSessionChecked(EGPackage pkg, UnitServer server, UnitSocketSession session)
			throws Exception {
		byte data[] = pkg.getData();
		int pos = 0;
		String callLetter = session.getUnitInfo().getCallLetter();
		String collectTime = EGTimeFormatUtil.getDateTime(pkg.getData(), pos, 6);
		pos += 6;
		int serialNo = Util.getShort(data, pos);
		pos += 2;
		int canFrameNum = data[pos++];
		StringBuilder sb = new StringBuilder();
		sb.append("[" + callLetter + "]");
		sb.append(" Recv Can Frame data,collectTime:");
		sb.append(collectTime);
		sb.append(";serialNo:");
		sb.append(serialNo);
		for (int i = 0; i < canFrameNum; i++) {
			int canId = Util.getInt(data, pos);
			pos += 4;
			sb.append(";canId:");
			sb.append(canId);
			byte[] canData = new byte[8];
			System.arraycopy(data, pos, canData, 0, 8);
			pos += 8;
			sb.append(";canData:");
			sb.append(HexUtil.byteToHexStr(canData));
		}
		logger_debug.debug(sb.toString());
		return true;
	}
}